import request from "@/utils/request";
import { AxiosPromise } from "axios";
import { MenuQuery, MenuVO, MenuForm } from "./types";

/**
 * 获取路由列表
 * @returns request
 */
export function listRoutes() {
	return request({
		url: "/api/v1/menus/routes",
		method: "get"
	});
}

/**
 * 获取菜单树形列表
 * @param queryParams
 * @returns request
 */
export function listMenus(queryParams: MenuQuery): AxiosPromise<MenuVO[]> {
	return request({
		url: "/api/v1/menus",
		method: "get",
		params: queryParams
	});
}

/**
 * 获取菜单下拉树形列表
 * @returns request
 */
export function getMenuOptions(): AxiosPromise<OptionType[]> {
	return request({
		url: "/api/v1/menus/options",
		method: "get"
	});
}

/**
 * 获取菜单表单数据
 * @param id
 * @returns request
 */
export function getMenuForm(id: number): AxiosPromise<MenuForm> {
	return request({
		url: "/api/v1/menus/" + id + "/form",
		method: "get"
	});
}

/**
 * 添加菜单
 * @param data
 * @returns request
 */
export function addMenu(data: MenuForm) {
	return request({
		url: "/api/v1/menus",
		method: "post",
		data: data
	});
}

/**
 * 修改菜单
 * @param id
 * @param data
 * @returns request
 */
export function updateMenu(id: string, data: MenuForm) {
	return request({
		url: "/api/v1/menus/" + id,
		method: "put",
		data: data
	});
}

/**
 * 删除菜单
 * @param id 菜单ID
 * @returns request
 */
export function deleteMenu(id: number) {
	return request({
		url: "/api/v1/menus/" + id,
		method: "delete"
	});
}
